let net = require('net');
const Frame = require("../src/net/Frame")


let HOST = '127.0.0.1';
let PORT = 4700;


var client = new net.Socket();
var frame = new Frame(client)
client.connect(PORT, HOST, function() {

    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
    // 建立连接后立即向服务器发送数据，服务器将收到这些数据

    setInterval(function () {
        frame.send({
            cmd : "hello" ,
            data : 'I am Chuck Norris!'
        });
    }, 1000)

});

frame.recv(function (data) {
    console.log('DATA: ' + JSON.stringify(data));
    // 完全关闭连接
    //client.destroy();
})

// 为客户端添加“data”事件处理函数
// data是服务器发回的数据
client.on('data', function(data) {
    console.log(data)
    frame.hook(data);
});



// 为客户端添加“close”事件处理函数
client.on('close', function() {
    console.log('Connection closed');
});



